#include "qpopupbutton.h"


QPopupButton::QPopupButton(QWidget *parent) :
    QPushButton(parent), m_pWidget(0)
{
    setCheckable(true);
    connect(this, SIGNAL(toggled(bool)), this, SLOT(show(bool)));
}

QWidget *QPopupButton::popupWidget()
{
    return m_pWidget;
}

void QPopupButton::setPopupWidget(QWidget *widget)
{
    m_pWidget = widget;
}

void QPopupButton::show(bool bShow)
{
    if (m_pWidget == 0) {
        return;
    }
    if (bShow) {
        QPoint pt = mapToGlobal(QPoint(0, height()));
        m_pWidget->move(pt.x(), pt.y());
        m_pWidget->show();
    } else {
        m_pWidget->hide();
    }
}
